package display {
	import sweatless.graphics.SmartCircle;
	import com.greensock.TweenMax;
	import assets.jazzturesexample.AHandCursorFrame;

	import flash.filters.GlowFilter;

	import assets.jazztures.AHandCursor;

	import flash.display.Sprite;

	public class CursorRenderer extends Sprite {
		private var hand : AHandCursor;
		private var color : uint;
				
		private var progressFrame:Sprite;
		private var progressCircle:SmartCircle;

		public function CursorRenderer() {
			mouseChildren=false;
			mouseEnabled=false;
			
			color = 0x999999 + Math.random() * 0x333333;
			hand = new AHandCursor();
			hand.x = -Math.round(hand.width / 2);
			hand.y = -Math.round(hand.height / 2);
			hand.filters = [new GlowFilter(color, 1, 10, 10, 1.5)];
			addChild(hand);
		}
		
		public function set progress(value:Number):void{
			progressCircle.finalAngle = value*360;
		}
		
		public function showProgress():void{
			progressFrame = new Sprite();
			addChild(progressFrame);
			progressFrame.alpha = 0;
			
			var background:AHandCursorFrame = new AHandCursorFrame();
			background.x = - Math.round(background.width / 2);
			background.y = - Math.round(background.height / 2);
			progressFrame.addChild(background);
			background.filters = [new GlowFilter(color, 1, 10, 10, 1.5, 1, false, true)];
			
			progressCircle = new SmartCircle(background.width*1.3, background.height*1.3, 0, 0);
			progressCircle.x = -progressCircle.width/2;
			progressCircle.y = -progressCircle.height/2;
			progressCircle.colors = [color];
			progressFrame.addChild(progressCircle);
			
			var progressMask:AHandCursorFrame = new AHandCursorFrame();
			progressMask.x = - Math.round(progressMask.width / 2);
			progressMask.y = - Math.round(progressMask.height / 2);
			progressFrame.addChild(progressMask);
			progressCircle.mask = progressMask;
						
			TweenMax.to(progressFrame, .5, {alpha:1});
		}
		
		public function hideProgress():void{
			TweenMax.to(progressFrame, .5, {alpha:0, scaleX:2, scaleY:2});
		}
	}
}